<?php
/**
 * @version     1.0.0
 * @package     com_sanpham
 * @copyright   Copyright (C) 2013. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 * @author      thinh <dinhducthinh88@yahoo.com> - http://
 */

// No direct access
defined('_JEXEC') or die;

/**
 * Sanpham helper.
 */
class TravelHelper
{
	/**
	 * Configure the Linkbar.
	 */
	public static function addSubmenu($vName = '')
	{
		JSubMenuHelper::addEntry(
			JText::_('COM_TRAVEL_TITLE_TOURS'),
			'index.php?option=com_travel&view=tours',
			$vName == 'tours'
		);
		
		JSubMenuHelper::addEntry(
				JText::_('COM_TRAVEL_TITLE_FIELDS'),
				'index.php?option=com_travel&view=fields',
				$vName == 'fields'
		);

	}

	/**
	 * Gets a list of the actions that can be performed.
	 *
	 * @return	JObject
	 * @since	1.6
	 */
	public static function getActions($categoryId = 0, $articleId = 0)
	{
		// Reverted a change for version 2.5.6
		$user	= JFactory::getUser();
		$result	= new JObject;
	
		if (empty($articleId) && empty($categoryId)) {
			$assetName = 'com_travel';
		}
		elseif (empty($articleId)) {
			$assetName = 'com_travel.category.'.(int) $categoryId;
		}
		else {
			$assetName = 'com_travel.tour.'.(int) $articleId;
		}
	
		$actions = array(
				'core.admin', 'core.manage', 'core.create', 'core.edit', 'core.edit.own', 'core.edit.state', 'core.delete'
		);

		foreach ($actions as $action) {
			$result->set($action,	$user->authorise($action, $assetName));
		}
	
		return $result;
	}
	
	/**
	 * Get a list of field type.
	 *
	 * @return	array	An array of JHtmlOption elements.
	 */
	public static function getTypeOptions()
	{
		$options[] = JHTML::_('select.option', 'checkbox', 'Check Box (Single)' );
		$options[] = JHTML::_('select.option', 'multicheckbox', 'Check Box (Muliple)' );
		$options[] = JHTML::_('select.option', 'multicheckboximage', 'Check Box (Muliple Images)' );
		$options[] = JHTML::_('select.option', 'date', 'Date' );
		$options[] = JHTML::_('select.option', 'select', 'Drop Down (Single Select)' );
		$options[] = JHTML::_('select.option', 'multiselect', 'Drop Down (Multi-Select)' );
		$options[] = JHTML::_('select.option', 'emailaddress', 'Email Address' );
		$options[] = JHTML::_('select.option', 'number', 'Number Text' );
		$options[] = JHTML::_('select.option', 'price', 'Price' );
		$options[] = JHTML::_('select.option', 'editor', 'Editor Text Area' );
		$options[] = JHTML::_('select.option', 'textarea', 'Text Area' );
		$options[] = JHTML::_('select.option', 'text', 'Text Field' );
		$options[] = JHTML::_('select.option', 'url', 'URL' );
		$options[] = JHTML::_('select.option', 'radio', 'Radio Button' );
		$options[] = JHTMLSelect::option ('radioimage','Radio Button (Image)');
		$options[] = JHTML::_('select.option', 'file', 'File' );

		return $options;
	}
	
	/**
	 * Get a list of Categories options
	 *
	 * @return	array An array of Object elements.
	 */
	public static function getCateOptions($parent = 0)
	{
		$options = new stdClass();
		$result = array();
		$db		= JFactory::getDbo();
		$query	= $db->getQuery(true);
	
		$query->select('a.id AS value, a.name AS text, a.published,a.parent');
		$query->from('#__travel_categories AS a');
		$query->where("a.published = 1 AND a.parent = $parent");
		$db->setQuery($query);
		$rows = $db->loadObjectList();

		foreach($rows as $key=>$row){
			 if ($row->parent == $parent) {
				$result[] = JHTML::_('select.option', $row->value, $row->text );

				//$options is a array of Object elements.
				$options = TravelHelper::getCateOptions($row->value);
				if ($options) {
					foreach($options as $option){
						// add Object element to array options
						$option->text = ' - '.$option->text ;
	                	//$result[] = $option;
	                	$result[] = JHTML::_('select.option', $option->value, $option->text );
					}
	            }
			 }
		}
		return $result;
	}
}